package com.ruoyi.bmxt.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.constant.BmxtConstants;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bmxt.domain.BmSpecialtyFee;
import com.ruoyi.bmxt.service.IBmSpecialtyFeeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专业学费管理Controller
 * 
 * @author 魏建波
 * @date 2023-02-20
 */
@RestController
@RequestMapping("/bmxt/specialtyFee")
public class BmSpecialtyFeeController extends BaseController
{
    @Autowired
    private IBmSpecialtyFeeService bmSpecialtyFeeService;

    /**
     * 查询专业学费管理列表
     */
    @PreAuthorize("@ss.hasPermi('bmxt:specialtyFee:list')")
    @GetMapping("/list")
    public TableDataInfo list(BmSpecialtyFee bmSpecialtyFee)
    {
        startPage();
        List<BmSpecialtyFee> list = bmSpecialtyFeeService.selectBmSpecialtyFeeList(bmSpecialtyFee);
        return getDataTable(list);
    }

    /**
     * 导出专业学费管理列表
     */
    @PreAuthorize("@ss.hasPermi('bmxt:specialtyFee:export')")
    @Log(title = "专业学费管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmSpecialtyFee bmSpecialtyFee)
    {
        List<BmSpecialtyFee> list = bmSpecialtyFeeService.selectBmSpecialtyFeeList(bmSpecialtyFee);
        ExcelUtil<BmSpecialtyFee> util = new ExcelUtil<BmSpecialtyFee>(BmSpecialtyFee.class);
        util.exportExcel(response, list, "专业学费管理数据");
    }

    /**
     * 获取专业学费管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bmxt:specialtyFee:query')")
    @GetMapping(value = "/{specialtyFeeId}")
    public AjaxResult getInfo(@PathVariable("specialtyFeeId") Long specialtyFeeId)
    {
        return success(bmSpecialtyFeeService.selectBmSpecialtyFeeBySpecialtyFeeId(specialtyFeeId));
    }

    /**
     * 新增专业学费管理
     */
    @PreAuthorize("@ss.hasPermi('bmxt:specialtyFee:add')")
    @Log(title = "专业学费管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmSpecialtyFee bmSpecialtyFee)
    {
        // 验证一个学校和层次不能重复添加
        if (BmxtConstants.NOT_UNIQUE.equals(bmSpecialtyFeeService.checkSchoolLevelSpecialtyNameUnique(bmSpecialtyFee)))
        {
            return error("添加失败，专业信息已存在");
        }
        return toAjax(bmSpecialtyFeeService.insertBmSpecialtyFee(bmSpecialtyFee));
    }

    /**
     * 修改专业学费管理
     */
    @PreAuthorize("@ss.hasPermi('bmxt:specialtyFee:edit')")
    @Log(title = "专业学费管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmSpecialtyFee bmSpecialtyFee)
    {
        // 验证一个学校和层次不能重复添加
        if (BmxtConstants.NOT_UNIQUE.equals(bmSpecialtyFeeService.checkSchoolLevelSpecialtyNameUnique(bmSpecialtyFee)))
        {
            return error("修改失败，专业信息已存在");
        }
        return toAjax(bmSpecialtyFeeService.updateBmSpecialtyFee(bmSpecialtyFee));
    }

    /**
     * 删除专业学费管理
     */
    @PreAuthorize("@ss.hasPermi('bmxt:specialtyFee:remove')")
    @Log(title = "专业学费管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{specialtyFeeIds}")
    public AjaxResult remove(@PathVariable Long[] specialtyFeeIds)
    {
        return toAjax(bmSpecialtyFeeService.deleteBmSpecialtyFeeBySpecialtyFeeIds(specialtyFeeIds));
    }
}
